package com.motionlog.adapter;

import java.util.List;

import com.motionlog.R;
import com.motionlog.model.Base;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class MyBaseAdapter extends BaseAdapter {

	LayoutInflater mInflater;
	List<? extends Base> mList;
	boolean mChecked = false;

	public MyBaseAdapter(Context context, List<? extends Base> baseList) {
		mInflater = LayoutInflater.from(context);
		mList = baseList;
	}

	public MyBaseAdapter(Context context, List<? extends Base> baseList,
			boolean checked) {
		mInflater = LayoutInflater.from(context);
		mList = baseList;
		mChecked = checked;
	}

	@Override
	public int getCount() {
		return mList.size();
	}

	@Override
	public Base getItem(int position) {
		return mList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if (convertView == null) {
			if (mChecked) {
				convertView = mInflater.inflate(
						R.layout.simple_list_item_multiple_choice, null);
			} else {
				convertView = mInflater
						.inflate(R.layout.select_list_item, null);
			}
		}
		TextView tv = (TextView) convertView.findViewById(R.id.name);
		tv.setText(getItem(position).name);

		return convertView;
	}
}
